home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/env python
-
- #
- # This file is part of OpenVIP (http://openvip.sourceforge.net)
- #
- # Copyright (C) 2002-2003
- # Michal Dvorak, Jiri Sedlar, Antonin Slavik, Vaclav Slavik, Jozef Smizansky
- #
- # This program is licensed under GNU General Public License version 2;
- # see file COPYING in the top level directory for details.
- #
- # $Id: thumbnail.py,v 1.7 2003/05/25 09:27:11 vaclavslavik Exp $
- #
-
- #
- # Generates thumbnail image for an input file.
- #
-
- import openvip, sys
- import Image
-
- if len(sys.argv) < 5:
- sys.stderr.write('Usage: %s infile outfile height frames\n' % sys.argv[0])
- sys.exit(1)
-
- height = int(sys.argv[3])
- frames = int(sys.argv[4])
-
- lib = openvip.Library()
-
- class ThumbMaker:
- def __init__(self):
- self.images = []
- self.all = []
- def add(self, image):
- self.images.append(image)
- def next(self):
- self.all.append(self.images)
- self.images = []
- def save(self, filename):
- frames = len(self.all[0])
- img = Image.new("RGB", (frames*width, len(self.all)*height))
- ypos = 0
- for images in self.all:
- for i in range(0,len(images)):
- img.paste(images[i], (i*width,ypos))
- ypos += height
- img.save(filename)
-
- # NB: video params based on first video track only:
- info = lib.get_file_info(sys.argv[1])
- if len(info.video_streams) > 0:
- track = info.video_streams[0]
- width = height * track.width / track.height
- else:
- track = info.audio_streams[0]
- width = height
-
- maker = ThumbMaker()
- dst = openvip.DestCallbackPIL(maker.add)
-
- for track in info.video_streams:
- task = lib.create_thumbnails_generator(sys.argv[1], track.name,
- width, height, frames, dst)
- task.render()
- maker.next()
- for track in info.audio_streams:
- task = lib.create_thumbnails_generator(sys.argv[1], track.name,
- width, height, frames, dst)
- task.render()
- maker.next()
- maker.save(sys.argv[2])
-